473,386 Members | 1,830 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.

Is this Valid Switch statement ?????

Hello friends,

I am new to C and I have written a code but
#include <stdio.h>
main()
{
init_funtion();
}
void init_funtion();
{
int i;
for (i =1; i < 10; i++)
{
switch (i)
{
case 1 :
{
printf("my vlaue is 1");
break;
}
case 2 :
{
printf(" my value is 2");
break;
}
and so on till case 9
}
}
}
but when I complile the error is "the statement for is of no effect" is
that mean in for loop I cannot define my switch satement......in general
switch statement can be written in for loop ???

please help me ....

I am waiting for your replies

with regards,

Sridhar.


Nov 14 '05 #1
6 1498
Sridhar_Gadda <sr**********@yahoo.com> scribbled the following:
Hello friends, I am new to C and I have written a code but
#include <stdio.h>
main()
{
init_funtion();
}
void init_funtion();
{
int i;
for (i =1; i < 10; i++)
{
switch (i)
{
case 1 :
{
printf("my vlaue is 1");
break;
}
case 2 :
{
printf(" my value is 2");
break;
}
and so on till case 9
}
}
}
but when I complile the error is "the statement for is of no effect" is
that mean in for loop I cannot define my switch satement......in general
switch statement can be written in for loop ??? please help me ....


Take the semicolon away from the end of your for loop line.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon
Nov 14 '05 #2
Joona I Palaste <pa*****@cc.helsinki.fi> spoke thus:
Take the semicolon away from the end of your for loop line.


Since there is no semicolon at the end of the line in question:
for (i =1; i < 10; i++)
I assume you're talking about the one at the end of this line :)
void init_funtion();


--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #3
ok thanks ...I see that my program is working and you can define Switch
statement inside forloop.

greetings

sridhar,

Nov 14 '05 #4
Christopher Benson-Manica <at***@nospam.cyberspace.org> scribbled the following:
Joona I Palaste <pa*****@cc.helsinki.fi> spoke thus:
Take the semicolon away from the end of your for loop line.
Since there is no semicolon at the end of the line in question:
> for (i =1; i < 10; i++) I assume you're talking about the one at the end of this line :)

> void init_funtion();


Right. Time to get stronger glasses, I think. =)

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
Nov 14 '05 #5
"Sridhar_Gadda" <sr**********@yahoo.com> writes:
I am new to C and I have written a code but
#include <stdio.h>
main()
{
init_funtion();
}
void init_funtion();
{
int i;
for (i =1; i < 10; i++)
{
switch (i)
{
case 1 :
{
printf("my vlaue is 1");
break;
}
case 2 :
{
printf(" my value is 2");
break;
}
and so on till case 9
}
}
}
but when I complile the error is "the statement for is of no effect" is
that mean in for loop I cannot define my switch satement......in general
switch statement can be written in for loop ???


That's not the same as the program you actually compiled, is it? The
error message was probably the result of a minor error in your code,
most likely an extra semicolon on the line with the "for". You've
posted code with *different* minor errors, particularly the extra
semicolon on the "void init_funtion() line. When I compiled the code
you posted (with the "and so on till case 9" commented out), I got a
syntax error, not a complaint about the for loop.

We can't tell you what the problem is unless you post the *exact* code
that you compiled. Don't re-type it, cut-and-paste it. And don't
paraphrase (the "and so on till case 9"), but reduce the code as much
as you can.

(BTW, it's spelled "function", not "funtion". C doesn't care whether
your identifiers are correctly spelled as long as you're consistent,
but your readers will care.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6
Sridhar_Gadda wrote:
Hello friends,

I am new to C and I have written a code but
#include <stdio.h>
main()
{
init_funtion();
}
void init_funtion();
{
int i;
for (i =1; i < 10; i++)
{
switch (i)
{
case 1 :
{
printf("my vlaue is 1");
break;
}
case 2 :
{
printf(" my value is 2");
break;
}
and so on till case 9
}
}
}
but when I complile the error is "the statement for is of no effect" is
that mean in for loop I cannot define my switch satement......in general
switch statement can be written in for loop ???

please help me ....

I am waiting for your replies

with regards,

Sridhar.


Try this. Look carefully at how it differs from your code.

#include <stdio.h>

void init_funtion(void)
{
int i;
for (i = 1; i < 4; i++) {
switch (i) {
case 1:
{
printf("my vlaue is 1");
break;
}
case 2:
{
printf("my value is 2");
break;
}
case 3:
{
printf("my value is 3");
break;
}
}
puts("");
}
}

int main(void)
{
init_funtion();
return 0;
}

--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #7

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

Similar topics

10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
5
by: Alvin Bruney | last post by:
Is a switch more efficient than an if statement? I observe thru the debugger that a switch statement jumps directly to its case handler where as an if statement examines all conditions...
3
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
1
by: Berko | last post by:
I'm having problems with a switch statement that is wrapped in a foreach statement so that each index in an array is evaluated against the switch statement. The switch/case will then return some...
25
by: v4vijayakumar | last post by:
'continue' within switch actually associated with the outer 'while' loop. Is this behavior protable? int ch = '\n'; while (true) { switch(ch) { case '\n': cout << "test"; continue; } }
12
by: | last post by:
Is it fine to call another method from Switch? Eg. Switch (stringVar) { case ("a"): somVar = "whatever"; Another_Method(); //call another method return;
6
by: Pallav singh | last post by:
In the Given below code Does case const-expression: do not have anny effect on do ...while(); loop Thanks Pallav Singh #include<stdio.h> #include<stdlib.h>
2
by: Phillip B Oldham | last post by:
What would be the optimal/pythonic way to subject an object to a number of tests (based on the object's attributes) and redirect program flow? Say I had the following: pets = {'name':...
13
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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,...

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.