473,508 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

if statement problem

1 New Member
c program in which both the if and else statements should execute
Jan 12 '07 #1
2 1557
Banfa
9,065 Recognized Expert Moderator Expert
It's really not clear what you mean but something like this would do it

Expand|Select|Wrap|Line Numbers
  1. #include "stdio.h"
  2.  
  3. int main(int argc, char **argp)
  4. {
  5.     int ctrl;
  6.  
  7.     for(ctrl = 0; ctrl<2; ctrl++)
  8.     {
  9.         if (ctrl == 0)
  10.         {
  11.             puts("In if block");
  12.         }
  13.         else
  14.         {
  15.             puts("In else block");
  16.         }
  17.     }
  18.  
  19.     return 0;
  20. }
  21.  
In this program both the if and else blocks will execute.
Jan 12 '07 #2
ramudukamudu
16 New Member
Hi, truely speaking both the if,else clause can't be executed simultaneously. But I had gone through a similar C puzzle. that is: what could be the if clause condition to print "Hellow World: in the below code?
if( XXXXX)
{
printf("Hello");
}
else
{
printf(" World.");
}

The possible Ans:

if( !printf("Hello") )
{
......
printf prints "Hello" and returns the no of words printed, so if condition will fail and else clause gets executed.
Jan 12 '07 #3

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

Similar topics

6
8158
by: DLP22192 | last post by:
I have the following single-line if statement that is evaluating true even though it shouldn't. I have never seen this before and I am concerned that this can happen in other areas of my code. ...
7
11418
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
11
50276
by: Colleyville Alan | last post by:
I posted that I was having trouble with a SQL statement that was working in the SQL window, but not in VBA. I have since discovered that when I create the string in VBA it is over 1023 characters...
3
4604
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
9
2349
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
5
1310
by: | last post by:
I have a module that's processed as an include file in a tradtional asp application that I'm migrating to dotnet. In one of the modules, there's an if statement that's gotten appended to over...
3
2805
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
2
6491
by: Rajat Katyal | last post by:
Hi: I prepare the statement for execution as follows: PREPARE query(text) as SELECT count(*) FROM transform_customer_billing where inv_no = $1; The problem is Iam not able to execute this...
6
2128
by: Twobridge | last post by:
I hope someone can help me out with my problem. I have found a sql statement that basically pulls all bills filed within a certain time period and the payments made on those bills with in the...
3
15861
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
0
7229
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
7129
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
7502
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
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3208
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
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
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
769
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.