Trying to have an output repeat

  • Thread starter magnifik
  • Start date
  • Tags
    Output
In summary, to make a program output repeat, you can use a loop statement, such as a for loop or a while loop, to iterate through a certain block of code multiple times. You can control the number of times the output repeats by setting a condition in the loop statement, and to avoid an infinite loop, you should make sure to include a way for the loop to exit. Additionally, you can use a counter variable or arrays and lists to control the order of the output and have multiple outputs repeating simultaneously by using nested loops or multiple loop statements.
  • #1
magnifik
360
0
How do you make a string repeat itself for a given number of times?
For example, if I wanted to make "3y" print out "yyy" on the screen (it prints "y" 3 times because the number in the input is 3).. how would i do this using functions?
 
Physics news on Phys.org
  • #2
you could just parse the input string; but of course, you will need to include some specifications, or the input/output you want can be very vague ('33y') can be 33 times of y or 3 times of 3y.
 

Related to Trying to have an output repeat

1. How can I make a program output repeat?

To make a program output repeat, you can use a loop statement, such as a for loop or a while loop, to iterate through a certain block of code multiple times.

2. Can I control how many times the output repeats?

Yes, you can control the number of times the output repeats by setting a condition in the loop statement. For example, you can specify a certain number of iterations or use a conditional statement to control when the loop should stop.

3. How do I avoid an infinite loop when trying to repeat an output?

To avoid an infinite loop, you should always make sure to include a way for the loop to exit, such as setting a condition or using a break statement. It is important to test your code and adjust the loop control accordingly to prevent infinite looping.

4. Is there a way to make the output repeat in a specific order?

Yes, you can use a counter variable and increment or decrement it in the loop statement to control the order of the output. You can also use arrays or lists to store the output and access it in a specific order within the loop.

5. Can I have multiple outputs repeating at the same time?

Yes, you can have multiple outputs repeating simultaneously by using nested loops or by incorporating multiple loop statements within your code. This allows for more complex and intricate patterns of output repetition.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
20
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
22
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Programming and Computer Science
Replies
29
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
31
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
3K
Back
Top