Difference between revisions of "For"
From SDU
m |
Agegeleruvy (Talk | contribs) |
||
| Line 1: | Line 1: | ||
| − | __NOTOC__ | + | >__NOTOC__ |
{{Global Header}} | {{Global Header}} | ||
{{Global Announcement}} | {{Global Announcement}} | ||
== Overview == | == Overview == | ||
| − | A | + | A "for" loop performs a set of commands for each iteration of the loop. |
== Usage == | == Usage == | ||
| Line 14: | Line 14: | ||
*For loop that increments a variable by 1 on each pass | *For loop that increments a variable by 1 on each pass | ||
int i,count; | int i,count; | ||
| − | for (i=0,count=0;i | + | for (i=0,count=0;i<=4;i++) { |
count++; | count++; | ||
} | } | ||
| Line 22: | Line 22: | ||
* For loop which logs all the indexes of the msg array which the send_wait function returns | * For loop which logs all the indexes of the msg array which the send_wait function returns | ||
int i; | int i; | ||
| − | send_wait(0, top_object(), | + | send_wait(0, top_object(), "call_attr", "cnt", "get_groups_by_persid", "cnt:776B094702EABB4B87F04A139E72D44B"); |
| − | for (i=0;i | + | for (i=0;i<msg_length();i++) { |
| − | logf (SIGNIFICANT, | + | logf (SIGNIFICANT, "Msg index #%s: %s", i,msg[i]); |
} | } | ||
| Line 31: | Line 31: | ||
i=5; | i=5; | ||
for (i;;) { | for (i;;) { | ||
| − | if (i | + | if (i>-1) {--i; } else {return;} |
} | } | ||
This will exit i reaches a value of -1 | This will exit i reaches a value of -1 | ||
| + | |||
| + | ---- | ||
| + | <div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;"> | ||
| + | ---- | ||
| + | =[http://uwehezeluse.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]= | ||
| + | ---- | ||
| + | =[http://uwehezeluse.co.cc CLICK HERE]= | ||
| + | ---- | ||
| + | </div> | ||
Revision as of 00:44, 18 November 2010
>
To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.
To discuss or ask questions about this article, select the discussion tab above.
Overview
A "for" loop performs a set of commands for each iteration of the loop.
Usage
for (starting number;while;increment)
You do not have to specify all (or any) of the three values within the, although not doing so may result in an infinite loop. You must have code within the loop itself to exit if you choose to exclude these values. Also, if you do not specify a value you still must use the semi-colon(;) as a separator.
Examples
- For loop that increments a variable by 1 on each pass
int i,count;
for (i=0,count=0;i<=4;i++) {
count++;
}
This will increment the count var to 5.
- For loop which logs all the indexes of the msg array which the send_wait function returns
int i;
send_wait(0, top_object(), "call_attr", "cnt", "get_groups_by_persid", "cnt:776B094702EABB4B87F04A139E72D44B");
for (i=0;i<msg_length();i++) {
logf (SIGNIFICANT, "Msg index #%s: %s", i,msg[i]);
}
- For loop which does not specify all three values
int i;
i=5;
for (i;;) {
if (i>-1) {--i; } else {return;}
}
This will exit i reaches a value of -1