Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-2007, 10:35 PM
pablo25 pablo25 is offline
Newbie
 
Join Date: Dec 2007
Posts: 2
Rep Power: 0
pablo25 is on a distinguished road
Default if statements help

Hey I am writing a AI mind (Trying) that. Its a creature in a world that at each timestep get a state update taht tells it "how its doing" the creature mind which is made up of if statements is similar logic to the code

let say the state the world sends back is

the current value of item A is : 0.754
the current value of item B is : 0.597
the current value of item C is : 0.813
the current value of item D is : 0.121

then the craetures code tells the creature what to do as defined by the following code



if( item A > 0.6)
do method A
if( item B > 0.4)
do method B
if( item C > 0.7)
do method C
if( item D > 0.1)
do method D





which of the follwing will be executed.. would i be right in sayind method A cos its first in line?
and if at the nest timestep if the value for A < 0.6 and the rest still hold or are even greater then it will be the if statement with method B
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-14-2007, 12:49 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,651
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

All of the methods will be executed. First it will check whether A is greater than 0.6 or not. If it's greater (like in your case) it will execute method A. When it has finished executing method A, it will move on in the code, and check B...
If you only want one of the methods to be executed you should use else if's. If you're doing that, then it will be the first of them (which is true) there'll get its method executed.
Code:
if(item A > 0.6)
    do method A // This will be executed
else if(item B > 0.4)
    do method B
...
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
if statements jack1234 C and C++ 3 11-05-2007 09:32 AM
Statements clookid PHP Tutorials 1 01-11-2007 09:42 PM
Java:Tutorial - Flow Control John Java Tutorials 0 12-09-2006 06:47 PM
Using conditional statements Sionofdarkness C and C++ 1 07-21-2006 05:46 PM


All times are GMT -5. The time now is 03:03 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads