473,498 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does "while(ifs)" works the same way "while(!eof.ifs())"?

1 New Member
Hello there.

Today, I was developing a college work software and then I saw thoe 2 types of while. My teacher asked me how does the "while(ifs)" (considering my ifstream was ifs) (that was the one I was using) should work, I didn't know what to answer.

Both of em works to check the enf of the file in, right? Whats the advantage in using while(ifs)? How does the "ifs" works.

Thanks in the advance. :)
Jun 6 '07 #1
1 1818
weaknessforcats
9,208 Recognized Expert Moderator Expert
A while loop continues as long as the condition is true.

True is not false. False is 0. Therefore, any non-zero value is true.

Functions that return a value become an instance of their return type. That is,

Expand|Select|Wrap|Line Numbers
  1. int MyFunction();
  2.  
  3. int result = MyFunction();   //return used to intialize result
  4.  
  5.  
So, by calling MyFunction you can use result in your while loop:

Expand|Select|Wrap|Line Numbers
  1. while(result != 0)
  2. {
  3.  
  4. }
  5.  
and you will stay in the loop as long as result is not zero.

Alternatively, you could code this loop to be:

Expand|Select|Wrap|Line Numbers
  1. while(result)
  2. {
  3.  
  4. }
  5.  
because result is true if it is not zero.

Alternatively, you can skip using result since it's not required to be an actual variable and recode the while loop to be:

Expand|Select|Wrap|Line Numbers
  1. while (MyFunction())
  2. {
  3.  
  4. }
  5.  
Nothing new happens here. MyFunction() is still called. But the return is put into a temporary int created by the compiler. That int is then tested by the while loop.

In summary, there are not different kinds of while loops. There are different ways of stating whether an expression is true. The loop merely evaluates the expression.
Jun 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1682
by: Lazlo Woodbine | last post by:
I'm trying to implement a dynamic menu using CSS/DHTML/JavaScript. The menu bar is implemented as hyperlinks so I can use the :hover :active etc. pseudo-styles. When moving from one item to...
21
2012
by: thomson | last post by:
Hi folks, Does any one have any idea which platform does GMAIL works, whether its JSP, ASPX or any other Regards thomson
7
2112
by: GS | last post by:
Hello, I'm receiving The state information is invalid for this page and might be corrupted error message when running code below. This happens on second post back. Why is it happening? My...
12
1443
by: raghu | last post by:
Hello Everyone, I have a doubt for a long time. consider a structure struct A{ int z; } struct n{ struct A *a; int *y; }*st;
2
1621
by: Miaaa Mukherjee | last post by:
Hello frdz, I have created ASP.Net website in which i have created the main page with the topmenu(which is of images),the middle menu(which is of different links like Home,Contact...
20
6819
by: Sanchit | last post by:
I want to know how does printf (stdio library function) works? Does this depand on complier (I am using gcc on Linix) Does it uses some buffer in which it stores all what needed to be printed...
1
4731
by: Saad Alam | last post by:
Hi, I have added a link in my page that will make my site home page in users browser. <a class="makefeahome" onClick="this.style.behavior='url(#default#homepage)';...
3
2146
by: arty | last post by:
i have set a flickr service using jsonp it consists of: a form wich makes a request to the json formated feed on the flickr server, works fine on ie and ff, but on safari if i ommit any text in...
4
1579
matheussousuke
by: matheussousuke | last post by:
Hi, I have just uploaded a website to server, it's working fine, at least for one thing, if login to it on my computer (localhost) the login works fine, but if I do the same on webserver, it doesn't...
0
1278
by: jaheda | last post by:
Dear friends, Happy tuesday,i have been tring to solve my problem i cound not solve my problem is below. Would you help me please to solve this issue i want to set tabkey=enter key on my webform, i...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.