473,626 Members | 3,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control statement in infinite looping concept from c programming

2 New Member
In the infinite looping statement in c in while loop why we have to put non-zero positive number inside that ? and why not i put negative value or zero
Jul 27 '17 #1
3 1852
weaknessforcats
9,208 Recognized Expert Moderator Expert
The control has to be true to enter the loop. Zero is false. Negative numbers are false.
Jul 27 '17 #2
donbock
2,426 Recognized Expert Top Contributor
I thought all nonzero int values, including negative numbers, were equally true.

I assume a literal value other than int, char, or bool (such as long or float) would either be illegal or undefined behavior. I don't know about unsigned int.

Best to limit yourself to the int values 0 or 1. The virtue of these values is they are consistent with common usage and also the C Standard guarantee that logical expressions (such as "i < 10") always evaluate to 0 or 1.
Jul 28 '17 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Negative numbers are false.

Oops.

Glad you caught that.
Jul 28 '17 #4

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

Similar topics

2
1565
by: Sigmund | last post by:
Hi, I would like to put an IF statement within the mail() function. I've tried this and searched around but haven't found anything written about this. Is it possible? I've been doing somethings like : mail ("Email", "Subject", "Body".if() {...}."", "From"); Sorry if this is a dumb question. BUT, if it works I will try similar things in SELECT statements.
6
1835
by: chandra.somesh | last post by:
I am having trouble understanding why the code given belows enters an infinite loop when a char is entered instead of an int. i.e.on subsequent looping ,control doesn't wait for user input and just keeps printing "Hello" infinitely. #include<iostream> using namespace std; int main()
6
2342
by: RdR | last post by:
Hi, Has anyone encountered infinite looping in Q Replication? This happens when I have a source DB2 table A going to a target DB2 table B, it also happens that the samne target table B is replicated back to source table A (true bi-directional replication scenario). Once I start replication on a master to master scenario the changes in A gets replicated to B but that change gets replicated back to A and so on creating an infinite loop. Is...
0
1947
by: cyshao | last post by:
Hi, My Friends: I have a program and I want to let machine automaticly auto it by using Windows task schedule. Sure, I can manually Create/Modify task in Windows task schedule. But I also hope to Create/Modify tasks by programming, for another program want to generate many tasks. Could you tell how to control windows task schedule by programming ? Thanks
5
3627
by: yusufjammy | last post by:
How to control or interface with parallel port in c++ programming .
1
2680
by: windscar | last post by:
Hello Everybody! I am a beginner that try to learn C++ programming. I work in Linux Ubuntu Karmic Koala (9.10) environment. I got a problem with getchar(). The function works well in a simple program. But when I use it in while (cond.) and switch (var.) , the function doesn't work, it doesn't even ask me to input character (including "\n"). Or maybe there are other reasons why getchar() doesn't work. I am sorry if I repost the same...
3
1979
by: mrklai | last post by:
I'm having a problem with infinite looping of my code. i am new to C++ and am writing a mortgage calculator for school assignment and my instructor is of no help. I ran across the faq/chap 15 on <iostream> and attempted to input the example within my code and receive nothing but error messages since...Can someone point out to me what I'm doing wrong PLEASE. /*Header Section*/ #include "stdafx.h" #include <iostream> #include <math.h>...
3
1307
by: Kumar2013 | last post by:
Hi, I would like to take a recordset and insert its entire contents into a table without looping. I know it can be done using SQL in VBA to achieve this. Thanks Kumar
0
8272
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8205
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8713
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8644
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8514
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5579
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1516
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.