Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Loop conditions problem

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
hi
i had a problem in how to implement the loop conditions .the problem is as follows:
int num,harray[],raaray[],rindex;
i want to check the condition whether value of num is less than or equal to the values of rarray [i] where i = 0 to rindex .incase this conditon is true i want to increment the value of num to num+1000 ,store the value of this num in haaray[0].(p.s rindex value is always less than the array size).and call another function called heap
Incase the conditon is false for all the values of raaray[rindex] then i want to insert haaray[0]=num and called the function called heap.
i have been trying to figure how to write down this code .my code what i have wriiten is as follows but i am not sure whether it is correct or not so please let me know
the code is as follows :
for(int u =0;u <rindex ;u++)
{
if (num <= raaray[u])then
{
num=num+10000;
haaray[0]=num
upheap(harray);
}
else
{
haaray[0]=num;
upheap(harray);
}
}

The doubt which i have is whether the if conditoin will check for all the i values or not .and i want to go to the assignment portion in the else case only after all the i values have been checked and not satisfied .but i am not sure whether this is implemented in this code which i have wriiten .Please let me know
Thanks
Lakshmi
p.s i was not sure whihch group to put up this question so i have also posted in the beginners level
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please don't crosspost. It wastes time and bandwith. And it makes the bartenders look like this:
And believe me, if you see one of them in person when they are like you will be like and everyone at javaranch will be :roll:
There is already a perfectly lovely answer to your question here:
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=33&t=004862
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    Bookmark Topic Watch Topic
  • New Topic