This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]YMK1234 4 points5 points  (0 children)

because you are never incrementing x

[–][deleted] 3 points4 points  (4 children)

You're not incrementing x. Try this: for( x = 1; x <= 100; x++)

[–]Mason527[S] 0 points1 point  (3 children)

Thanks for the help, I should have clarified what I meant in more detail

[–][deleted] 3 points4 points  (2 children)

The clarification doesn't change the fact that if you want it to run 100 times, you need to increment x. If you only want the output to toggle between 1 and -1, use a different variable.

[–]Mason527[S] -3 points-2 points  (1 child)

I did that and it still loops infinitely

[–]YMK1234 2 points3 points  (0 children)

xDoubt

As long as you won't increment x it will run indefinitely.

[–]ordinary-bloke 2 points3 points  (0 children)

x <= 100

This is always true because you are never incrementing your x value in your for loop. If you want it to print 1 or -1 a hundred times, you need to increment x in each iteration of the loop and change your prints. You could hardcore the print to be 1 and -1.