Glitch in For-loop

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 796 Views - Last Post: 03 September 2018 - 10:10 PM Rate Topic: *---- 2 Votes

#1 daygamer   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 110
  • Joined: 21-August 18

Glitch in For-loop

Posted 03 September 2018 - 07:58 AM

Hi,

Works perfect untill added extra values in each List:


                            List.Add(array[0]);
                            List.Add(array[1]);
                            List.Add(array[2]);
                            List.Add(array[3]);

                             for (int q = 2; q < List.Count; q++)
                            {
                                Console.WriteLine(List[q] + List[q-2]);
                                
                            }



Why does it have extra Writeline beetween every correct output when added more than 2 values?

Any correcting code available?

it becomes extra output in between every output without any value containing

This post has been edited by daygamer: 03 September 2018 - 07:59 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Glitch in For-loop

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14498
  • View blog
  • Posts: 58,118
  • Joined: 12-June 08

Re: Glitch in For-loop

Posted 03 September 2018 - 08:01 AM

Explain what you are entering and what you are seeing. It is not clear.
Was This Post Helpful? 0
  • +
  • -

#3 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2662
  • View blog
  • Posts: 4,256
  • Joined: 21-June 11

Re: Glitch in For-loop

Posted 03 September 2018 - 08:02 AM

Please post a compilable piece of code that reproduces the problem. As-is there's too much missing information (such as the types and contents of `List` and `array`) to see what might be wrong.
Was This Post Helpful? 0
  • +
  • -

#4 daygamer   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 110
  • Joined: 21-August 18

Re: Glitch in For-loop

Posted 03 September 2018 - 08:14 AM

View Postmodi123_1, on 03 September 2018 - 08:01 AM, said:

Explain what you are entering and what you are seeing. It is not clear.


this should explain exactly what is going on in the visualstudio cmd:


        2018-09-03 18:12:21
        title: t

        message: v
yt
        2018-09-03 18:12:21
        Titel:
ty
        message:

        2018-09-03 18:12:29
        Titel: yt

        message: ty



You see?

This post has been edited by daygamer: 03 September 2018 - 08:15 AM

Was This Post Helpful? 0
  • +
  • -

#5 daygamer   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 110
  • Joined: 21-August 18

Re: Glitch in For-loop

Posted 03 September 2018 - 08:30 AM

There is alot of codes but cant show all
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2662
  • View blog
  • Posts: 4,256
  • Joined: 21-June 11

Re: Glitch in For-loop

Posted 03 September 2018 - 08:47 AM

You're not supposed to show it all, you're supposed to show enough to compile, run and demonstrate the problem. If you're not able to reproduce the problem in, say, 30 lines of code, then how can we be able to find the problem given only 10?
Was This Post Helpful? 0
  • +
  • -

#7 daygamer   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 110
  • Joined: 21-August 18

Re: Glitch in For-loop

Posted 03 September 2018 - 08:59 AM

                            Console.WriteLine("\n\Title: ");
                            array[0] = Console.ReadLine();
                            Console.WriteLine("\n\tMessage: ");
                            array[1] = Console.ReadLine();
                            array[2] = "\n\t" + DateTime.Now + "\n\tTitel: ";
                            array[3] = "\n\t" + "Message: ";
                           
                            Lista.Add(array[0]);
                            Lista.Add(array[1]);
                            Lista.Add(array[2]);
                            Lista.Add(array[3]);

                                  for (int q = 2; q < Lista.Count; q++)

                                {
                                    Console.WriteLine(Lista[q] + Lista[q - 2]);
                                }



this code is in bool loop, switch function. SO don't worry this has correlation to eachother.

Would need all help available.

This types out as requested but somewhat glitches in every second line of output.

This post has been edited by Skydiver: 03 September 2018 - 09:22 AM
Reason for edit:: Removed unnecessary quote .No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#8 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2662
  • View blog
  • Posts: 4,256
  • Joined: 21-June 11

Re: Glitch in For-loop

Posted 03 September 2018 - 09:09 AM

That code still does not compile. Anyway, it now seems like your question might be "Why do I get empty lines when I print a string that starts with \n". Is that your question? If so, the answer is: "Because \n starts a new line, so if you print \n at the beginning of a line, you end up with an empty line".
Was This Post Helpful? 1
  • +
  • -

#9 daygamer   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 110
  • Joined: 21-August 18

Re: Glitch in For-loop

Posted 03 September 2018 - 09:18 AM

I can tell you this algorithm is wrong. Also is it real you dont see this wrong in code? You been member since 2011 and i started programming coirse 25 days ago

This post has been edited by Skydiver: 03 September 2018 - 09:21 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#10 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6502
  • View blog
  • Posts: 22,258
  • Joined: 05-May 12

Re: Glitch in For-loop

Posted 03 September 2018 - 09:24 AM

daygamer: Please stop quoting the post above yours. Just use the big Reply button or the Fast Reply area. How many times do we need to remind you?

The algorithm is not necessarily wrong. Your understanding of strings, and how WriteLine() works seems to be lacking.
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14498
  • View blog
  • Posts: 58,118
  • Joined: 12-June 08

Re: Glitch in For-loop

Posted 03 September 2018 - 09:27 AM

@Daygamer - second time I have to warn you to not insult the community and folk. Ease up there buck-a-roo.
Was This Post Helpful? 0
  • +
  • -

#12 daygamer   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 110
  • Joined: 21-August 18

Re: Glitch in For-loop

Posted 03 September 2018 - 09:27 AM

What is your suggestion then? What should i use for getting correct values in correct order?
Was This Post Helpful? 0
  • +
  • -

#13 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2662
  • View blog
  • Posts: 4,256
  • Joined: 21-June 11

Re: Glitch in For-loop

Posted 03 September 2018 - 09:29 AM

View Postdaygamer, on 03 September 2018 - 06:18 PM, said:

I can tell you this algorithm is wrong.


What algorithm?

Quote

Also is it real you dont see this wrong in code?


Except for the obvious compilation errors (which obviously aren't present in your real code), there is nothing inherently wrong with your code. I think your question might be why you're getting empty lines in the output and I've already answered that. If that was not your question, you should clarify.

Quote

You been member since 2011 and i started programming coirse 25 days ago


You sound like you're accusing me of something and I'm honestly not sure of what (maybe of purposefully misunderstanding your question, which I assure you I did not), but I'm starting to find that a bit rude. I've done nothing except asking for missing information (without which it would have been or is impossible to answer your question) and trying to help you.
Was This Post Helpful? 0
  • +
  • -

#14 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 120
  • View blog
  • Posts: 849
  • Joined: 05-December 13

Re: Glitch in For-loop

Posted 03 September 2018 - 09:29 AM

A book
Was This Post Helpful? 3
  • +
  • -

#15 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6502
  • View blog
  • Posts: 22,258
  • Joined: 05-May 12

Re: Glitch in For-loop

Posted 03 September 2018 - 09:31 AM

Consider this simple, compilable, and runnable code that demonstrates what happens when you use string with and without embedded linefeeds in them:
using System;
using System.IO;

class Test
{
    static void Main()
    {
        string foo = "Foo";
        string bar = "Bar";
        string withoutLineFeed = foo + bar;
        string withLineFeed = foo + "\n" + bar;
        
        Console.WriteLine(">>");
        Console.WriteLine(withoutLineFeed);
        Console.WriteLine("<<");

        Console.WriteLine(">>");
        Console.WriteLine(withLineFeed);
        Console.WriteLine("<<");

        Console.WriteLine(">>");
        Console.Write(withoutLineFeed);
        Console.WriteLine("<<");

        Console.WriteLine(">>");
        Console.Write(withLineFeed);
        Console.WriteLine("<<");
    }
}



Output:
>>
FooBar
<<
>>
Foo
Bar
<<
>>
FooBar<<
>>
Foo
Bar<<


Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2