473,386 Members | 1,817 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,386 software developers and data experts.

switch trouble

I've got the switch structure right:

switch ($i) {
case 1:
print "i equals 1";
break;

default:
print "i doesn't equal 1";
}

But no matter what I do it always executes the default code block. How
do I pass a value for $i to the program?

--
Dinguss (Michael Bradley-Robbins)

http://www.douglasguitars.com/
Jul 17 '05 #1
2 1447
Are you setting a value for $i?

At the top of the code put:
$i = 1;
and then see what happens.

If you're talking about running the script from the command line and
want to pass a value for $i, check out

http://us3.php.net/reserved.variables

and read about argv. If you're running it as a webpage, it'll need to
come from somewhere...probably (but not necessarily) an HTML form.

Jul 17 '05 #2
Dinguss wrote:
I've got the switch structure right:
Indeed, it is correct syntax.
switch ($i) {
case 1:
print "i equals 1";
break;

default:
print "i doesn't equal 1";
}

But no matter what I do it always executes the default code block.


Where is the value for $i coming from, i.e. where is $i set?

--
Oli

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Rudi Hansen | last post by:
I dont seem to be able to find the switch statement in Python. I would like to be able to do switch(var) case 1 : print "var = 1" case 2: print "var = 2"
1
by: David Whitfield | last post by:
Hi All... I am a beginning .NET developer and am using C# with ASP.NET. I am having trouble with switch statements, can anyone help? When I run the below code, I receive an error "Compiler Error...
3
by: Mike Wiseley | last post by:
I created a desktop shortcut with "C:\Program Files\Microsoft Office\MSAccess.exe" "C:\My Documents\CopyAToB.mdb" /pwd "password: The trouble is that when running this shortcut, it prompts first...
65
by: He Shiming | last post by:
Hi, I just wrote a function that has over 200 "cases" wrapped in a "switch" statement. I'm wondering if there are performance issues in such implementation. Do I need to optimize it some way? ...
8
by: Sivas | last post by:
Hi, Can anyone tell me why this does not work: --------------------------------------------- float b = 2.51F; switch(b) {
24
by: Mark | last post by:
Hi - how can I get a switch statement to look for a range of values? I have: function payCalc(field, field2) switch(field.value) { case 0-50: field2.value="lower band"; case 51-99:...
22
by: Technoid | last post by:
Is it possible to have a conditional if structure nested inside a conditional switch structure? switch(freq) { case 1: CASENAME if (variable==1) { do some code }
4
by: priyanka | last post by:
Hi there, I had a question. Is there any way of testing a string value in a switch statement. I have about 50 string values that can be in a string variable. I tried cheking them with the if...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
6
by: Zoner | last post by:
Hey. This is my first post on this forum, and I'm just coming for a little help. I just started to teach myself Java yesterday, and i am having trouble writing a switch statement. The error: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.