Simplified C Block programming problem for-loop

Support Communities Code Generation and Implementation Simplified C Block programming problem for-loop

This topic contains 1 reply, has 2 voices, and was last updated by  Albert Dunford 3 weeks, 3 days ago.

  • Author
    Posts
  • #40352

    Liong Han Wen
    Participant

    Hi All,

    I have problem writing for-loop in simplified C block. Below is my code:

    {
    static double total=0;
    static double square=0;
    for(int N=0,N<=1000;N++)
    {
    square=x1*x1;
    total=total+square;
    }
    }

    when I press check code, the software pop out a lot of error message as shown in attachment file. Does anyone can help me point out what mistake I did?I am using PSIM 9.0

    Attachments:
    You must be logged in to view attached files.
  • #40405

    Albert Dunford
    Participant

    Hi,

    there are few errors with your code, move the variable deceleration out of the “for( ; ; )” statement, the compiler we use for C does not like a variable declared here. Second you are missing a semi-colon after “N=0” you are using a comma when it needs to be a “;”. changes in bold below

    {
    static double total=0;
    static double square=0;
    int N = 0;

    for(N=0;N<=1000;N++) { square=x1*x1; total=total+square; } }

You must be logged in to reply to this topic.