473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

If loop

Parul Bagadia
188 100+
IDE used is Microsoft Visual C++ 6.0
in the inner loop even when the value of second is 3 it executes that for loop... that should not happen even when we use to conditions for validity of for loop.
Expand|Select|Wrap|Line Numbers
  1.  
  2. for(first=0;first<2;first++)
  3.  {
  4.   for(second=1;second<3,column>-1;second++,column--)
  5.   {
  6.    if(first==second)
  7.     second++;   
  8.     store=(matrix[1][first]*matrix[2][second]-matrix[1][second]*matrix[2][first])*(matrix[0][column]);
  9.     if(column==1)
  10.      store=store*-1;
  11.     add=store+add;
  12.   }
  13.  }
  14.  
.
One more thing in Visual C++ 6.0 is -1^2; square of -1 is coming as 3...
Which function is actually getting evaluated?
Whats the operator for Exponent?
I tried with almost all operators.. in all those even % was also unexplainable.
Jan 11 '09 #1
2 1776
Tassos Souris
152 100+
Check the relational expression in your for loop construct.
Expand|Select|Wrap|Line Numbers
  1. second<3,column>-1
  2.  
Whether or not the body of the for loop executes depends on the value of column and not on the value of second because you are using the comma operator.
The comma operator works like this:
  • The expression which is at the left is evaluated first
  • Then the expression on the right is evaluated
  • The value of the expression that was evaluated last (the right one) is returned
So, what you get in your for loop relational expression is a true or false value whether column is greater than -1 or not, cause that expression is evaluated last. The expression second < 3 is evaluated but the result has no impact on the for relational expression.

The ^ operator is the bitwise exclusive-or operator; surely not what you want. Take a look at the <math.h> header file.
Jan 11 '09 #2
Bassem
344 100+
Both for loop's conditions have to be True to end it.
So if column is 5 the loop will be executed for 5 times, because 5 is greater than 3 - the condition of second.
Now you have 2 probabilities
1- column < 3 the loop will executed 3 times
2- column > 3 the loop will executed column times

In math.h, you'll find the most mathematical operations used; pow, exp, ...etc.
Jan 11 '09 #3

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

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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
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,...

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.