Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

For loop

Posted on 2006-11-01
11
Medium Priority
?
290 Views
Last Modified: 2010-04-15
Hi,

How is the following loop interpreted?

Thank you.

for (i=56;i>0;){
0
Comment
Question by:IAJWDDIY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 17850729
Set i to 56.

Then, as long as i is greater than 0
execute the following compound statement.
0
 
LVL 86

Expert Comment

by:jkr
ID: 17850730
'i' is initialized to 56 and the loop is executed as long as 'i' does not drop below '1'. However, since the 'loop expression' (as in "for( [init-expr]; [cond-expr]; [loop-expr] )") does not change 'i', it has to be altered inside the loop body to meet that criteria.
0
 
LVL 30

Expert Comment

by:callrs
ID: 17850733
Loop starts with i equal to 56
Continues to loop while i is greater than 0
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Expert Comment

by:callrs
ID: 17850751
0
 
LVL 30

Expert Comment

by:callrs
ID: 17850856
Need to reduce i, else you have infinite loop. This will reduce it by one on each iteration of the loop:

for (i=56;i>0;i--){
0
 
LVL 86

Expert Comment

by:jkr
ID: 17850877
>>Need to reduce i

What was unclear about "However, since the 'loop expression' [...] does not change 'i', it has to be altered inside the loop body to meet that criteria."?
0
 

Author Comment

by:IAJWDDIY
ID: 17850985
So if there is a statement like:

 a=z[i-] ; b=z[i-].....

inside the loop would this reduce?

Thanks
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 17851056
Well, if they were like

a=z[i--] ; b=z[i--];

Yes, they would, e.g.

for (i=56;i>0;){

a=z[i--];
}
0
 

Author Comment

by:IAJWDDIY
ID: 17851079
Thank you.
0
 
LVL 30

Expert Comment

by:callrs
ID: 17851128
>>What was unclear

Nothing wrong with more clarity, adding the words "infinite loop', and giving an i--  option.   : )
0
 
LVL 30

Expert Comment

by:callrs
ID: 17851173

IAJWDDIY, it's almost hidden away, but there's a "Split points" link in open questions at the bottom ;)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question