Is for looping working excellently? And other for loop questions
#1
Posted 09 August 2018 - 03:21 AM
#2: In global script if a for loop is not in a while(true) loop does the for loop continue on?
#3: In an ffc script does a for loop go on forever while Link is on screen with the ffc if such a for loop is not in a while(true) loop?
#4: All up above questions but replace for with do until.
#5: Top 3 up above questions but replace for with the word with.
#2
Posted 09 August 2018 - 07:25 AM
You need Waitframe() in any loop that is infinite; this for the most part means only in while(true) loops. You also need Waitframe() wherever you need to... wait a frame.
A for() loop runs until a condition is met. So for instance, for(int i = 0;i<10;i++) will run whatever is in the body of the loop 10 times, with the value of i going up by one each time. Once the condition (in this case, i<10) is no longer met, the loop stops and the code after the loop begins. Do beware creating an infinite loop accidentally; make sure that the condition can be made false by something in the loop, or if it is supposed to be made false by something the player does, be sure to include Waitframe().
If anything is BELOW the while(true) loop in a global script, it will not ever run. If it is ABOVE a while(true) loop, it will run when the game starts until the condition is no longer true, and the while(true) loop WILL NOT BEGIN RUNNING until AFTER the for loop is done.
I'd recommend checking out some online coding tutorials (java, c++, etc) because loops like this function much the same in those languages as they do in ZScript!
#3
Posted 09 August 2018 - 10:54 AM
Any type of loop can be infinite or not. It simply depends on whether the condition will ever become false.
do-while loops are almost the same as while loops; the difference is that a do-while loop always runs at least once, whether its condition is true or not. They're not used very often in ZScript. Unless you have a specific reason to prefer do-while, use a while loop instead.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users